package com.ctgu.rabbitmq.service.impl;

import com.ctgu.rabbitmq.rabbitmq.lazyQueue.LazyQueueConfig;
import com.ctgu.rabbitmq.service.LazyQueueService;
import com.ctgu.rabbitmq.utils.ApiResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

/**
 * @ ClassName LazyQueueServiceImpl
 * @ Author Alex2
 * @ Date 2025/9/1 11:36
 **/
@Log4j2
@Service
public class LazyQueueServiceImpl implements LazyQueueService {

    private final RabbitTemplate rabbitTemplate;

    public LazyQueueServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }


    @Override
    public ApiResult lazyQueue() {
        String message = "Hello World";
        rabbitTemplate.convertAndSend(
                LazyQueueConfig.LAZY_EXCHANGE,
                LazyQueueConfig.LAZY_ROUTING_KEY,
                message
        );
        log.info("发送惰性队列消息: {}", message);
        return ApiResult.success("发送惰性队列消息: ", message);
    }
}
